package com.siqi.hr.system.organization.entity;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 员工对象实体
 * @author    xiaogq
 */
public class Employee {
    private static final long serialVersionUID = 1612200339223824419L;

    public Employee() {
    }

    public Employee(String id) {
        this.id = id;
    }

    /**
     * 主键id
     */
    private String id;

    /**
     * 员工名称
     */
    private String name;

    /**
     * 员工工号(登陆名)
     */
    private String jobNumber;

    /**
     * 创建者
     */
    private String createUser;

    /**
     * 创建时间
     */
    private Date createDate;

    /**
     * 更新者
     */
    private String updateUser;

    /**
     * 拥有者
     */
    private String haveUser;

    /**
     * 修改时间
     */
    private Date updateDate;

    /**
     * 密码
     */
    private String password;

    /**
     * 所属部门
     */
    private Dept dept;

    /**
     * 所属角色
     */
    private Role role;

    /**
     * 联系电话
     */
    private String phone;

    /**
     * 企业邮箱
     */
    private String email;

    /**
     * 密码修改时间
     */
    private Date passUpdateDate;

    /**
     * 最近登陆时间
     */
    private Date latstLoginDate;

    /**
     * 头像
     */
    private String headImage;

    /**
     * 停用标记
     */
    private boolean flag;

    /**
     * 性别
     */
    private int sex;

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Date getCreateDate() {
        return this.createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    public Date getUpdateDate() {
        return this.updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Dept getDept() {
        return this.dept;
    }

    public void setDept(Dept dept) {
        this.dept = dept;
    }

    public boolean isFlag() {
        return this.flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public String getJobNumber() {
        return this.jobNumber;
    }

    public void setJobNumber(String jobNumber) {
        this.jobNumber = jobNumber;
    }

    public String getPhone() {
        return this.phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Date getPassUpdateDate() {
        return this.passUpdateDate;
    }

    public void setPassUpdateDate(Date passUpdateDate) {
        this.passUpdateDate = passUpdateDate;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Date getLatstLoginDate() {
        return latstLoginDate;
    }

    public void setLatstLoginDate(Date latstLoginDate) {
        this.latstLoginDate = latstLoginDate;
    }

    public String getHeadImage() {
        return this.headImage;
    }

    public void setHeadImage(String headImage) {
        this.headImage = headImage;
    }

    public int getSex() {
        return sex;
    }

    public void setSex(int sex) {
        this.sex = sex;
    }

    public String getCreateUser() {
        return createUser;
    }

    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }

    public String getUpdateUser() {
        return updateUser;
    }

    public void setUpdateUser(String updateUser) {
        this.updateUser = updateUser;
    }

    public String getHaveUser() {
        return haveUser;
    }

    public void setHaveUser(String haveUser) {
        this.haveUser = haveUser;
    }

    /**
     * 用户登录时获取用户、部门、角色信息
     * @author xiaogoingqin
     */
    public static class empAndDepAndRoleField extends Employee implements RowMapper<Employee> {
        public synchronized Employee mapRow(ResultSet rs, int index) throws SQLException {
            //设置登录用户信息
            Employee employee = new Employee();
            employee.setId(rs.getString("t3_id"));
            employee.setName(rs.getString("t3_name_varchar"));
            employee.setJobNumber(rs.getString("t3_job_number_varchar"));
            employee.setPassword(rs.getString("t3_password_varchar"));
            employee.setHeadImage(rs.getString("t3_head_img"));
            employee.setFlag(rs.getBoolean("t3_flag_bit"));

            //设置部门信息
            Dept dept = new Dept();
            dept.setId(rs.getLong("t3_pk_t_2_1"));
            dept.setName(rs.getString("t2_name_varchar"));
            dept.setCreateDate(rs.getDate("t2_create_date_datetime"));
            dept.setUpdateDate(rs.getDate("t2_update_date_timestamp"));
            dept.setParent(new Dept(rs.getLong("t2_pk_t_2_1")));
            dept.setDeptRank(rs.getString("t2_dept_rank_varchar"));
            dept.setFlag(rs.getBoolean("t2_flag_bit"));
            dept.setDeptAddress(rs.getString("t2_dept_address_varchar"));
            dept.setIsParent(rs.getBoolean("t2_isparent_bit"));
            dept.setIcon(rs.getString("t2_icon_varchar"));
            dept.setDescription(rs.getString("t2_dept_description_textarea"));
            employee.setDept(dept);
            //设置角色信息
            Role role = new Role();
            role.setId(rs.getString("t3_pk_t_1_1"));
            role.setIsAdmin(Boolean.valueOf(rs.getBoolean("t_1_isadmin")));
            role.setLoginModule(rs.getString("t1_loginModule_varchar"));
            employee.setRole(role);
            return employee;
        }
    }

    /**
     * 获取员工基础字段,id，name,jobNumber
     * @author ChenL
     */
    public static class getEmpBaseInfo extends Employee implements RowMapper<Employee> {
        public synchronized Employee mapRow(ResultSet rs, int index) throws SQLException {
            Employee employee = new Employee();
            employee.setId(rs.getString("id"));
            employee.setName(rs.getString("name_varchar"));
            employee.setJobNumber(rs.getString("job_number_varchar"));
            return employee;
        }
    }

}
